
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>骡窝日报详情</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/newsContent.css">
    <script src="/js/plugins/jrender/jrender.js"></script>
    <script src="/js/common.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
    <script src="/js/plugins/dialog/dialog.min.js"></script>


</head>

<body>
<div class="newsDetail">
    <div>
        <a href="javascript:history.go(-1);" style="position: absolute;top: 10px;left: 22px;">
            <span><i class="fa fa-chevron-left fa-2x" style="color: white;"></i></span>
        </a>
        <img render-src="coverUrl">

        <div class="container">
            <div class="row typeRow">
                <div class="col-12">
                    <span class="type" render-html="subTitle"></span>
                </div>

            </div>

            <div class="detail">
                <h2 class="title" render-htlm="title"></h2>
                <div class="content" render-html="dailyContent.content"></div>
            </div>
        </div>

        <hr>
        <!--相关推荐-->
        <h6 class="module-title">相关推荐</h6>
        <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
            <div id="travelsCommends">
                <div class="carousel-inner" render-loop="list">

                    <div class="carousel-item">
                        <a render-key="list.id" render-fun="handle">
                            <img class="d-block w-70" width="100%" height="20px"
                                 render-src="list.coverUrl">
                            <span class="recommend" render-html="list.title"></span>
                        </a>
                    </div>

                </div>
            </div>
            <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                <span class="sr-only"></span>
            </a>
            <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                <span class="sr-only"></span>
            </a>
        </div>
        <hr>

        <div class="operation">
            <div class="d-flex justify-content-between">
                <div class="p-2"><i></i></div>
                <div class="p-2  flex-fill" id="commentBtn1"><i class="fa fa-star-o" .btn-scid="collectBtn"
                                                                style="font-size:20px">收藏</i>
                </div>
            </div>
        </div>
    </div>

</div>
<script>
    $(function () {
        //点击收藏判断用户是否有登录
        $("#commentBtn1").click(function (d) {
            if (!getUser()){
                $(document).dialog({
                    type : 'confirm',
                    closeBtnShow: true,
                    content: '亲!您还未登录,点击确定按钮将回到登录页面',
                    onClickConfirmBtn: function(){
                        window.location="/mine/simpleProfiles.html"
                    },
                    onClickCancelBtn : function(){
                    }
                });
            }
        })
        //判断当前用户是否登录
        if (getUser()) {
            //回显当前用户,思路用当前用户的ID和游记ID查询数据库
            $.get("/users/"+getUser().id+"/daily/collect",{dailyId:getParams().id}, function (data) {
                console.log(data);
                //2.如果有值就是已收藏,否则就是未收藏
                if (data.success) {
                    //3.修改五角星样式样式
                    //删除原本样式的星星
                    $(".fa-star-o").removeClass("fa fa-star-o");
                    //在添加实心的五角星颜色红色
                    $("#commentBtn1").addClass("fa fa-star").attr('style', 'color:yellow;width:100px');
                    isCollect(0)
                } else {
                    isCollect(1)
                }
            })
        }
    })
    //抽取判断收藏还是取消
    function isCollect(i) {
        var counts = 0;
        //绑定收藏按钮
        $("#commentBtn1").click(function () {
            console.log(123456789);
            counts++;//计数器用来判断用户点击取消收藏还是添加收藏
            if (counts % 2 == i) {
                // 用户点击次数为单数就是新增,双数就是取消

                //删除原本样式的星星
                $(".fa-star-o").removeClass("fa fa-star-o");
                //在添加实心的五角星颜色红色
                $("#commentBtn1").addClass("fa fa-star").attr('style', 'color:yellow;width:100px');

                //加入收藏
                $.post("/users/collect", {userId: getUser().id, dailyId: getParams().id}, function (data) {
                    $(th).html("已收藏").addClass("btn-danger");
                })

                $(document).dialog({
                    content: '已添加到我的收藏',
                });
            } else {
                //点击取消收藏添加空心五角星颜色黑色
                $("#commentBtn1").addClass("fa fa-star-o").attr('style', 'color:black;width:100px')
                $.ajax({//删除收藏
                    type: "POST",
                    url: "/users/daily/collect",
                    //data: "_method=DELETE&dailyId="+dailyId+"&userId="+userId+"",
                    data: {_method: "DELETE", dailyId:getParams().id, userId: getUser().id},
                    success: function (msg) {
                    }
                });
                $(document).dialog({
                    content: '已取消收藏',
                });
            }
        })
    }
</script>


<script>
    $(function () {
        //获取日报ID
        var id = getParams().id;
        //发送ajax请求
        $.get("/dailys/" + id, function (data) {
            //喧染数据
            $(".newsDetail").renderValues(data);
        })

        $.get("/dailys", {state: 2}, function (data) {
            console.log(data);
            setTimeout(function () {
                $("#travelsCommends").renderValues(data, {
                    handle: function (ele, val) {
                        ele.href = "/dailyContent.html?id=" + val;
                    }
                });
                $(".carousel-item:first").addClass("active");
            }, 100);


            //默认选择第一个来显示

        });

    })


</script>

</body>

</html>
